package org.icnmasjid.member.webapp.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.beanutils.BeanUtils;

import org.icnmasjid.member.Constants;
import org.icnmasjid.member.model.Login;
import org.icnmasjid.member.service.LoginManager;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

public class LoginController implements Controller {
    private final Log log = LogFactory.getLog(LoginController.class);
    private LoginManager loginManager = null;

    public void setLoginManager(LoginManager loginManager) {
        this.loginManager = loginManager;
    }

    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response)
    throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'handleRequest' method...");
        }

        Login login = new Login();
        // populate object with request parameters
        BeanUtils.populate(login, request.getParameterMap());

        List logins = loginManager.getLogins(login);

        return new ModelAndView("loginList", Constants.LOGIN_LIST, logins);
    }
}
